<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.lagou.pojo.Resume"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    request.setCharacterEncoding("utf-8");
   

%>
<html>
<head>
    <title>列表查询</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<h2>我是服务器：${pageContext.request.localPort}</h2>
<h2>当前sessionId：${pageContext.session.id}</h2>
<%

    List<Resume> list = (List) request.getAttribute("list");
%>
<a href="/resume/edit">
<button type="button" class="btn btn-primary btn-xs" >添加</button>
</a>
  <table style="border: beige;background-color: #ffe4c4" border="1px" id="ta" style="text-align: center;">
      <tr>
          <th id="def" style="display: none" >id</th>
          <th id="name">姓名</th>
          <th id="address">地址</th>
          <th id="phone">手机号码</th>
          <th colspan="2" style="text-align: center;">操作</th>
      </tr>
      <%
          for(Resume resume:list){
      %><tr>
    <td style="display: none"><%=resume.getId()%></td>
    <td><%=resume.getName()%></td>
    <td><%=resume.getAddress()%></td>
    <td><%=resume.getPhone()%></td>
      <td><span onclick="toEdit(<%=resume.getId()%>)" style="cursor: pointer;">修改</span></td>
    <td><span onclick="deleteById(<%=resume.getId()%>)" style="cursor: pointer;">删除</span></td>
</tr>
    <% }%>
</table>
</body>
<script type="text/javascript">
    function toEdit(id){
        console.log("id="+id);
        window.location.href = "/resume/edit?id="+id;
    }
    function deleteById(data) {
        var id = data;
        console.log("id = ",id);
        console.log("data = ",data);
        var value = {};
        value.id = id;
        $.ajax({
            type: "POST",
            dataType: "json",
            data:value,
            url: "${pageContext.request.contextPath}/resume/delete",
            async: false,
            error: function (data) {
                alert("删除错误!原因为:"+data);
            },
            success: function (data) {
                location.reload();
            }
        });
    }
</script>
</html>
